package no.rmz.chez.chess.movement;

import java.util.Collection;
import java.util.LinkedList;

import no.rmz.chez.chess.board.Coord;

public final class Direction extends Coord {

    private final static Collection<Direction> NEWS = new LinkedList<>();
    private final static Collection<Direction> DIAGONALS = new LinkedList<>();
    private final static Collection<Direction> ALL_DIRECTIONS = new LinkedList<>();
    private final static Collection<Direction> KNIGHTS_DIRECTIONS = new LinkedList<>();

        
    private Direction(final int x, final int y) {
        super(x, y);
    }

    private Direction add(Direction a) {
        int newX = getX() + a.getX();
        int newY = getY() + a.getY();
        return new Direction(newX, newY);
    }
    
    public final static Direction N  = new Direction(0, -1);
    public final static Direction E  = new Direction(-1, 0);
    public final static Direction W  = new Direction(1, 0);
    public final static Direction S  = new Direction(0, 1);
    public final static Direction NE = N.add(E);
    public final static Direction NW = N.add(W);
    public final static Direction SE = S.add(E);
    public final static Direction SW = S.add(W);
 
    static {
        for (int i = -1; i <= 1; i += 2) {
            for (int j = -2; j <= 2; j += 4) {
                KNIGHTS_DIRECTIONS.add(new Direction(i, j));
                KNIGHTS_DIRECTIONS.add(new Direction(j, i));
            }
        }
        NEWS.add(N);
        NEWS.add(E);
        NEWS.add(W);
        NEWS.add(S);
        DIAGONALS.add(NE);
        DIAGONALS.add(NW);
        DIAGONALS.add(SE);
        DIAGONALS.add(SW);
        ALL_DIRECTIONS.addAll(DIAGONALS);
        ALL_DIRECTIONS.addAll(NEWS);
    }
  

    public static synchronized Collection<Direction> getAllDirections() {
        return ALL_DIRECTIONS;
    }

    public static synchronized Collection<Direction> getDiagonals() {
        return DIAGONALS;
    }

    public synchronized static Collection<Direction> getNEWS() {
        return NEWS;
    }
    
     public static Iterable<Direction> getKnightsDirections() {
        return KNIGHTS_DIRECTIONS;
    }
}
